//
//  UserModel.m
//  华春网络
//
//  Created by 丁 一 on 2018/4/11.
//  Copyright © 2018年 丁 一. All rights reserved.
//

#import "UserModel.h"
#import "Base_Key.h"
#import "HiJonesClass.h"
#import "JPUSHService.h"

@implementation UserModel

+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{

             };
}

+ (UserModel *)info
{
    NSDictionary *userInfo = [NSUserDefaults dictionaryForKey:UserDefaultsKey];
    UserModel *user        = [UserModel mj_objectWithKeyValues:userInfo];
    return user;
}

+ (void)setInfo:(NSDictionary *)info
{
    NSMutableDictionary *lindic=[NSMutableDictionary new];
    
    [lindic setValue:[info objectForKey:@"userid"] forKey:@"userid"];
    [lindic setValue:[info objectForKey:@"phone"] forKey:@"phone"];
    [lindic setValue:[info objectForKey:@"logo"] forKey:@"logo"];
    [lindic setValue:[info objectForKey:@"name"] forKey:@"name"];
    [lindic setValue:[info objectForKey:@"sex"] forKey:@"sex"];
//    [lindic setValue:[info objectForKey:@"password"] forKey:@"password"];
    [lindic setValue:[info objectForKey:@"briday"] forKey:@"briday"];
    
    [NSUserDefaults setObject:lindic forKey:UserDefaultsKey];
}

+ (void)clearUser
{
    if ([UserModel info].userid) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:UserDefaultsKey];
    }
    [DEFAULTS removeObjectForKey:@"UserChendGeNgFanc"];
}

+ (void)setChangeCar:(NSString *)car{
    NSDictionary *userInfo = [NSUserDefaults dictionaryForKey:UserDefaultsKey];
    NSMutableDictionary *lindic=[[NSMutableDictionary alloc] initWithDictionary:userInfo];
    NSDictionary *cardic = [HiJonesClass carinfo:car];
    if (cardic) {
        [lindic setObject:[cardic objectForKey:@"carlogo"] forKey:@"carlogo"];
        [lindic setObject:[cardic objectForKey:@"carname"] forKey:@"carname"];
        [lindic setObject:[cardic objectForKey:@"cartypename"] forKey:@"cartypename"];
        [lindic setObject:car forKey:@"car"];
        [lindic setObject:@"0" forKey:@"carok"];
    }
    [NSUserDefaults setObject:lindic forKey:UserDefaultsKey];
    
    
    [JPUSHService setTags:[[NSSet alloc] initWithObjects:[NSString stringWithFormat:@"car%@",[lindic objectForKey:@"car"]], nil] completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
        if (iResCode==0) {
            NSLog(@"成功");
        }else{
            NSLog(@"失败");
        }
    } seq:1.0];
}

+ (void)setChangeCarok:(NSString *)carok{
    NSDictionary *userInfo = [NSUserDefaults dictionaryForKey:UserDefaultsKey];
    NSMutableDictionary *lindic=[[NSMutableDictionary alloc] initWithDictionary:userInfo];
    [lindic setObject:carok forKey:@"carok"];
    [NSUserDefaults setObject:lindic forKey:UserDefaultsKey];
}

+ (void)setChangeLogo:(NSString *)Logo{
    NSDictionary *userInfo = [NSUserDefaults dictionaryForKey:UserDefaultsKey];
    NSMutableDictionary *lindic=[[NSMutableDictionary alloc] initWithDictionary:userInfo];
    [lindic setObject:Logo forKey:@"logolist"];
    [NSUserDefaults setObject:lindic forKey:UserDefaultsKey];
}

@end
